//
//  MainViewController.m
//  KL
//
//  Created by mac on 15/12/14.
//  Copyright © 2015年 zhouxubin. All rights reserved.
//

#import "MainViewController.h"
#import "LifeToolsViewController.h"
#import "NavViewController.h"
#import "MahuaViewController.h"
#import "JokesViewController.h"
#import "UMSocial.h"
#import "MahuaCell.h"
#import <SVProgressHUD.h>

@interface MainViewController () <UMSocialUIDelegate>

@end

@implementation MainViewController

#pragma mark - 设置主题颜色
+ (void)initialize {
    UITabBar *tabBar = [UITabBar appearance];
    [tabBar setTintColor:[UIColor orangeColor]];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 添加子控制器
    [self addChildViewControllers];
    
    // 添加通知观察者
    [KLNotificationCenter addObserver:self selector:@selector(didShareButton:) name:@"didShareButton" object:nil];
    
}

#pragma mark - 通知的响应事件
- (void)didShareButton:(NSNotification *)noti {
    MahuaCell *mahuaCell = noti.object;
    //注意：分享到微信好友、微信朋友圈、微信收藏、QQ空间、QQ好友、来往好友、来往朋友圈、易信好友、易信朋友圈、Facebook、Twitter、Instagram等平台需要参考各自的集成方法
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:nil
                                      shareText:mahuaCell.contentLabel.text
                                     shareImage:mahuaCell.pictureView.image
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToWechatSession, UMShareToWechatTimeline,nil]
                                       delegate:self];
}

#pragma mark - UMSocialUIDelegate
- (void)didCloseUIViewController:(UMSViewControllerType)fromViewControllerType {
    KLLog(@"%s", __func__);
    
    
}

//实现回调方法（可选）：
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    //根据`responseCode`得到发送结果,如果分享成功
    if(response.responseCode == UMSResponseCodeSuccess)
    {
        //得到分享到的微博平台名
        NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
    }
}

#pragma mark - 添加子控制器
- (void)addChildViewControllers {
    // 添加麻花控制器
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Mahua" bundle:nil];
    MahuaViewController *vc = [sb instantiateInitialViewController];
    // 设置title
    vc.title = @"麻花";
    vc.tabBarItem.image = [UIImage imageNamed:@"tabbar_home"];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_home_selected"];
    [self addChildViewController:vc];
    
    // 添加生活工具控制器
    LifeToolsViewController *lifeVc = [[LifeToolsViewController alloc] init];
    [self setUpTabBarItem:lifeVc norImage:@"tabbar_profile" selImage:@"tabbar_profile_selected" titli:@"生活工具"];  
}

#pragma mark - 设置tabbar的图片
- (void)setUpTabBarItem:(UIViewController *)vc norImage:(NSString *)norImage selImage:(NSString *)selImage titli:(NSString *)title {
    NavViewController *nav = [[NavViewController alloc] initWithRootViewController:vc];
    
    vc.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:norImage];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selImage];
    
    [self addChildViewController:nav];
}

@end
